var moduleApp=angular.module('moduleApp',['ui.router','oc.lazyLoad','pagination']);
/*,'ngFileUpload'*/
moduleApp.config(function ($provide, $compileProvider, $controllerProvider, $filterProvider) {
    moduleApp.controller = $controllerProvider.register;
    moduleApp.directive = $compileProvider.directive;
    moduleApp.filter = $filterProvider.register;
    moduleApp.factory = $provide.factory;
    moduleApp.service = $provide.service;
    moduleApp.constant = $provide.constant;
});

/**
 * 由于整个应用都会和路由打交道，所以这里把$state和$stateParams这两个对象放到$rootScope上，方便其它地方引用和注入。
 * 这里的run方法只会在angular启动的时候运行一次。
 * @param  {[type]} $rootScope
 * @param  {[type]} $state
 * @param  {[type]} $stateParams
 * @return {[type]}
 */
moduleApp.run(function($rootScope, $state, $stateParams,$location,$http,$templateCache,$window,$timeout) {
    var protocol= window.location.protocol
    var host = window.location.host;
    $rootScope.basePath=protocol+"//"+host+'/';
    var stateChangeSuccess = $rootScope.$on('$stateChangeSuccess', stateChangeSuccess);
    function stateChangeSuccess($rootScope) {
        $templateCache.removeAll();
    }

    $rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams){
        $rootScope.isActive = function(){   /*/!*设置点击的菜单的样式为active*!/*/
            var str = "/login";
            var href=toState.url;
            var index = href.indexOf("/");
            var index2 = href.indexOf("?");
            if(index != -1){
                if(index2!=-1){
                    str = href.substring(index,index2);
                }else{
                    str = href.substring(index,href.length);
                }
            };
            return str;
        }();
    });

});

//moduleApp.config(function($ocLazyLoadProvider){
//    $ocLazyLoadProvider.config({
//        debug:false,
//        events:false
//    });
//});


/**
 * 配置路由。
 * 注意这里采用的是ui-router这个路由，而不是ng原生的路由。
 * ng原生的路由不能支持嵌套视图，所以这里必须使用ui-router。
 * @param  {[type]} $stateProvider
 * @param  {[type]} $urlRouterProvider
 * @return {[type]}
 */
moduleApp.config(function($stateProvider,$urlRouterProvider,$locationProvider){
    $urlRouterProvider.otherwise('/login');
    $stateProvider
        .state('login',{
            url:'/login',
            views:{
                '':{
                    templateUrl:'page/login.html?v=4b67f58969',
                    controller:'LoginController'
                },
                'topMenu@login':{
                    templateUrl:'page/menu.html?v=63e25f9374',
                    controller:'MenuController'
                }
            },
            resolve:{
                load:['$ocLazyLoad',function($ocLazyLoad){
                    return $ocLazyLoad.load([
                        'js/controller/login.js?v=80595adc82'
                    ])
                }]
            }
        })
        .state('investment',{
            url:'/investment',
            views:{
                '':{
                    templateUrl:'page/investment.html?v=b628f01398',
                    controller:'InvestmentController'
                },
                'topMenu@investment':{
                    templateUrl:'page/menu.html?v=63e25f9374',
                    controller:'MenuController'
                }
            },
            resolve:{
                load:['$ocLazyLoad',function($ocLazyLoad){
                    return $ocLazyLoad.load([
                        'js/controller/investment.js?v=226bf6535b'
                    ])
                }]
            }
        })
        .state('order',{
            url:'/order',
            views:{
                '':{
                    templateUrl:'page/order.html?v=1a28d94b5f',
                    controller:'OrderController'
                },
                'topMenu@order':{
                    templateUrl:'page/menu.html?v=63e25f9374',
                    controller:'MenuController'
                }
            },
            resolve:{
                load:['$ocLazyLoad',function($ocLazyLoad){
                    return $ocLazyLoad.load([
                        'js/controller/order.js?v=c1bd490dfc'
                    ])
                }]
            }
        })
        .state('account',{
            url:'/account',
            views:{
                '':{
                    templateUrl:'page/account.html?v=e68627bc31',
                    controller:'AccountController'
                },
                'topMenu@account':{
                    templateUrl:'page/menu.html?v=63e25f9374',
                    controller:'MenuController'
                },
                'leftMenu@account':{
                    templateUrl:'page/leftMenu.html?v=5dc1ab017a'
                }
            },
            resolve:{
                load:['$ocLazyLoad',function($ocLazyLoad){
                    return $ocLazyLoad.load([
                        'js/controller/account.js?v=ba595ae5c0'
                    ])
                }]
            }
        })
})





